// main.go
package main

import (
	"embed"
	"log"

	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"

	"your_project/backend/services" // 请替换为你的实际模块路径
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
	// 初始化数据库服务
	dbService, err := services.NewDatabaseService("accounting.db")
	if err != nil {
		log.Fatalf("Failed to initialize database: %v", err)
	}
	defer dbService.Close() // 假设你在DatabaseService中实现了Close方法

	// 创建应用实例，该实例将绑定到前端
	app := NewApp(dbService)

	// 启动Wails应用
	err = wails.Run(&options.App{
		Title:  "我的记账工具",
		Width:  1024,
		Height: 768,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
		OnStartup:        app.startup,
		Bind: []interface{}{
			app,
		},
	})
	if err != nil {
		log.Fatal(err)
	}
}
